import Vue from "vue";
import store from "../store";
// 自定义指令
Vue.directive("btnPerm", {
  // 父级未渲染 不能操作父节点
  bind: function(el, binding, vnode) {
    // 操作dom
    if (binding.def.hasBtnPerm(binding.value)) {
      el.className = el.className + "  show_button";
    }
  },
  // 操作父节点
  inserted: function(el) {
  },
  update: function() {
  },
  componentUpdated: function() {
  },
  unbind: function() {
  },
  hasBtnPerm: function(params) {
    const button = store.getters["app/buttonPermission"]; // 请求权限数据
    const roles = store.getters["app/roles"]; // 获取角色
    if (roles.includes("admin")) {
      return true;
    }
    return button.indexOf(params) !== -1;
  }
});
